<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>留学生管理系统</title>
        <link rel="stylesheet" href="${path}/css/admin2.css">
        <!--<link rel="stylesheet" href="${path}/css/coursemanage-kb.css"/>-->
        <style>
            #score-setting{
                margin: 15% auto;
                padding: 10px;
                width: 420px;
                height: 340px;
            }
            #marktable input{
            	margin:0px 10px;
            	width:40%;
            }
        </style>
        <script>
            var _current_item = "#scoreRecord";
        </script>
        <script>
 
            function setSelectChecked(selectId, checkValue){  
            	
                var select = document.getElementById(selectId);  
                for(var i=0; i<select.options.length; i++){  
                    if(select.options[i].value == checkValue){  
                        select.options[i].selected = true;
                        break;  
                    }  
                }  
            };
            
           
        </script>
        
        <script type="text/javascript" src="${path}/js/jquery.min.js"></script>
    </head>
    <body>
    ${message!}
        <div id="above-mask">
            <div id="score-setting" class="pannel hide">
                <div class="close-container">
                    <a class="close" onclick="$('#above-mask, #mask, #score-setting').hide();">×</a>
                </div>
                <div id="pb">
                    <form name="form1" method="post">
                        <table>
                            <tr>
                                <td><div>平时成绩</div></td>
                                <td><input name="usual" value="${usual!}" type="text" id="num" placeholder="平时成绩" required></td>
                            </tr>
                            <tr>
                                <td><div>实验成绩</div></td>
                                <td><input name="experiment" value="${experiment!}" type="text" id="num2"  placeholder="实验成绩"></td>
                            </tr>
                             <tr>
                                <td><div>其他成绩</div></td>
                                <td><input name="other" value="${other!}" type="text" id="num4" placeholder="其他成绩"></td>
                            </tr>
                            <tr>
                                <td><div>期末成绩</div></td>
                                <td><input name="final" value="${final1!}" type="text" id="num3"  placeholder="期末成绩"></td>
                            </tr>
                           
                            <tr>
                                <td><div>打分方式</div></td>
                                <td>
                                    <select name="selectGrade" id="select1">					
                                        <option ${hundredSelect!}>百分制</option>
                                        <option ${fiveSelect!}>五级制</option>
                                    </select>
                                    
                                </td>
                            </tr>
                        </table>
                        <button onclick="send1()" type="button" style="margin: 10px auto; display: block;" ${access!}>确定</button>
                    </form>
                </div>
            </div>
            <div id="fileupload-pannel" class="fileupload pannel hide">
                <div class="close-container">
                    <a class="close" onclick="$('#above-mask, #mask, #fileupload-pannel').hide();">×</a>
                </div>
                <form id="uploadForm" action="${path}/teaScoreInput/importGrade?testNo=${testNo!}" method="post" enctype="multipart/form-data" name="fileForm">
                    <div style="margin-top: 30px;"> 上传文件：（支持Excel工作簿 .xls/.xlsx格式文件）</div>
                    <input id="fileCover" class="left" readonly="readonly" placeholder="导入excel文件" type="text" style="width: 280px; height: 22px;">
                    <button onclick="$('#uploadFile').click();return false;" style="background: #aaa">浏览文件</button>
                    <input type="file" name="uploadFile" required="required" id="uploadFile" style="display:none" onchange="$('#fileCover').val($(this).val());">
                    <div>
                        <button type="submit"  style="display: block; margin: 0 auto;">提交</button> 
                    </div>
                </form>
            </div>
        </div>
        <div id="mask"></div>
        <!--header-->
        <div id="header"></div>
        <div id="main">
            <div id="side-menu"></div>
            <div id="container">
                <div id="inner-border">
                <div class="admin-content">
                <div class="am-tabs am-margin" data-am-tabs>
                
                        
                 </div>  
                </div><div class="am-tabs-bd">
                    <div class="gr">
                        <div>
                            <button id="pbo" onclick="$('#above-mask, #mask, #score-setting').show()" ${access!}>比例设定</button>
                            <button type="button" style="width:100px" onclick="window.location.href = '${path}/teaScoreInput/gradeModel?testNo=${testNo!}'" ${access!}>模版下载</button>
                            <button onclick="$('#above-mask, #mask, #fileupload-pannel').show()" ${access!}>成绩导入</button>
                            <button type="button" style="width:100px" onclick="window.location.href = '${path}/teaScoreInput/reset?testNo=${testNo!}'" ${access!}>重置</button>
                        </div>
                        <div>
                        注：A-优秀，B-良好，C-中等，P-及格，F-不及格。<br>
                        <form id="markingtable">
                            <table id="marktable" style="width:100%">
                                <thead>
                                    <tr>
                                    <td>护照号</td> 
                                    <td>姓</td>
                                    <td>名</td>
                                    <td>专业</td> 
                                    <td>入学年份</td> 
                                    <td>入学季度</td>
                                    <td id="usual_grade" style="width:11%">平时成绩${usual!}%</td>
                                    <td id="exper_grade" style="width:11%">实验成绩${experiment!}%</td> 
                                    <td id="final_grade" style="width:11%">其他成绩${other!}%</td>
                                    <td id="other_grade" style="width:11%">期末成绩${final1!}%</td>
                                    <td style="width:7%">总评成绩</td>

                                    </tr>	
                                </thead>
                                <tbody id="tbody">
                                <#if students?exists>
                                <#list students as r>
                                    <tr>
										
                                    <td><input type="hidden" value="${r.passportNo}">${r.newpassportNo}</td> 
                                    <td>${r.firstName}</td>
                                    <td>${r.lastName}</td>
                                    <td>${r.majorName}</td> 
                                    <td>${r.eduStartDate}</td> 
                                    <td>${r.eduSeason}</td>
	
                                    
                                    <#if system=="五级制无">
                                    <td><select name="showUsual" id="${r.passportNo}1">
                                    		<option value="00"> </option>
                                            <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                           
                                        </select></td>
                                    <td><select name="showUsual" id="${r.passportNo}2">
                                    <option value="00"> </option>
                                            <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                            
                                        </select></td> 
                                    <td><select name="showUsual" id="${r.passportNo}3">
                                    <option value="00"> </option>
                                            <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                            
                                        </select></td> 
                                    <td><select name="showUsual" id="${r.passportNo}4">
                                    <option value="00"> </option>
                                            <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                             <option value="旷考">旷考</option>
                                            <option value="作弊">作弊</option>
                                        </select></td>
                                        </#if>
                                    <#if system=="百分制无">	
                                    <td><input id="${r.passportNo}1"></td>
                                    <td><input id="${r.passportNo}2"></td> 
                                    <td><input id="${r.passportNo}3"></td> 
                                    <td><input id="${r.passportNo}4">
                                    <select name="showUsual">
                                    <option value="正常">正常</option>
                                             <option value="旷考">旷考</option>
                                            <option value="作弊">作弊</option>
                                        </select>
                                    </td>
                                    </#if>
                                    <#if system=="百分制">	
                                    <td><input name="showUsual" id="${r.passportNo}1" type="text" value="${r.dailyGrade!}" ${access!}></td>
                                    <td><input name="showExperiment" id="${r.passportNo}2" type="text" value="${r.experimentalGrade!}" ${access!}></td> 
                                    <td><input name="showFinal" id="${r.passportNo}3" type="text" value="${r.otherGrade!}" ${access!}></td> 
                                    <td><input name="showOther" id="${r.passportNo}4" type="text" value="${r.finalGrade!}" ${access!}>
                                     <select name="type" id="${r.passportNo}5" ${access!}>
                                    <option value="正常">正常</option>
                                             <option value="旷考">旷考</option>
                                            <option value="作弊">作弊</option>
                                        </select>
                                        <script>
                                            $(document).ready(function(){
                                                setSelectChecked("${r.passportNo}5","${r.finalGrade!}");
                                            })
                                        </script></td>
                                    </#if>
                                    <#if system=="五级制">	
                                    <td>
                                        <select name="showUsual" id="${r.passportNo}1" ${access!}>
                                        <option value="00"></option>
                                            <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                            
                                        </select>
                                        <script>
                                            $(document).ready(function(){
                                                setSelectChecked("${r.passportNo}1","${r.dailyGrade!}");
                                            })
                                        </script>
                                    </td>
                                    <td>

                                        <select name="showExperiment" id="${r.passportNo}2" ${access!}>
                                        <option value="00"></option>
                                            <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                            
                                        </select>
                                        <script>
                                            $(document).ready(function(){
                                                setSelectChecked("${r.passportNo}2","${r.experimentalGrade!}");
                                            })
                                        </script>

                                    </td>
                                    <td>
                                        <select name="showOther" id="${r.passportNo}3" ${access!}>
                                        <option value="00"></option>
                                           <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                            
                                        </select>					
                                        <script>
                                            $(document).ready(function(){
                                                setSelectChecked("${r.passportNo}3","${r.otherGrade!}");
                                            })
                                        </script>
                                    </td>
                                    <td>
                                        <select name="showFinal" id="${r.passportNo}4" ${access!}>
                                        <option value="00"></option>
                                           <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                             <option value="旷考">旷考</option>
                                            <option value="作弊">作弊</option>
                                        </select>					 
                                        <script>
                                            $(document).ready(function(){
                                                setSelectChecked("${r.passportNo}4","${r.finalGrade!}");
                                            })
                                        </script>
                                    </td>	
                                    </#if>     
                                    
                                    <td>${r.grade!}</td>

                                    </tr>
                                </#list>
                                </#if>
                                </tbody>	
                            </table>

                            </form>

                        </div>
                        <button id="saveBt" onclick="saveGrade()" ${access!}>保存</button>
                        <button id="submitBt" onclick="submitGrades()" ${access!}>提交</button>
                    </div>
                  </div>
            </div>

            </div>
        </div>  
           		<div id="footer"></div>
        
        <script type="text/javascript" src="${path}/js/teacher-main-appearance.js"></script>
         <script src="${path}/js/amazeui.min.js"></script>
        
        	<!-- DataTables JavaScript -->
        <script src="${path}/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetHiddenNodes.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTd.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTds.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetColumnData.js"></script>
        <script src="${path}/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
        <script type="text/javascript">		
        
        $(document).ready(function () {
        	$('#marktable').DataTable({
                responsive: true,
                ordering: false,
                searching: true,
                "bLengthChange": false,
                "bRetrieve": true,
                "bFilter": true,//过滤功能

            });
            if("${status!}"!=""){ alert("${status!}");}
            
        });
     function send1(){
    	 var usual=document.getElementById("num").value;
         if(usual.trim()==""|usual=="0"){
             usual=0;
         }
         var experiment=document.getElementById("num2").value;
         if(experiment.trim()==""|experiment=="0"){
             experiment=0;
         }
         var final1=document.getElementById("num3").value;
         if(final1.trim()==""|final1=="0"){
             final1=0;
         }
         var other=document.getElementById("num4").value;
         if(other.trim()==""|other=="0"){
             other=0;
         }
        var select1 = document.getElementById("select1");
        var select = getSelectedValue(select1);
        //alert(select);
        $.ajax({
            type:"POST",
            url:"${path}/teaScoreInput/setGrade",
            dataType:"json",
            data:{
            	usual:usual,
            	experiment:experiment,
            	final1:final1,
            	other:other,
            	select:select,
            	testNo:"${testNo}",
            },success:function(data){
                      alert("比例设定成功。");
                     // alert(usual+"ssss");
                      window.location.href = "${path}/teaScoreInput/gradeSelected?testNo=${testNo}&usual="+usual+"&experiment="+experiment+"&final1="+final1+"&other="+other+"&select="+select+"&systemtemp=1"; 
                     /*  sendtemp(data); */
                    },
			 error:function(data){
            	alert("比例设定失败，默认平均百分之25，百分制。");
                    },
         });  
         //else{
         //	alert("比例和不等于100,请重新输入");
         //}
     }
     
     /*获取select的value*/
     /* function sendtemp(data){
     alert(data.systemtemp),
      $.ajax({
            type:"POST",
            url:"${path}/teaScoreInput/gradeSelected",
            data:{
            	usual:data.usual,
            	experiment:data.usualexperiment,
            	final1:data.final1,
            	other:data.other,
            	select:data.select,
            	systemtemp:data.systemtemp,
            	testNo:"${testNo}",
            }, 
            success:function(){
            alert(data.systemtemp+"aaaa");
                      alert("第二步come on!");
                      window.location.href = "${path}/teaScoreInput/gradeSelected?testNo=${testNo} & usual="+usual;
                    },
			 error:function(data){
				alert("error");
                    }, 
         }); 
     } */
     

     function getAllNodes(_id)
        {
        	return $('#' + _id).dataTable().fnGetNodes();
        }
    function saveGrade(){
    
    	var usual=document.getElementById("num").value;
    	var experiment=document.getElementById("num2").value;
    	var final1=document.getElementById("num3").value;
        var other=document.getElementById("num4").value;
        var select1 = document.getElementById("select1");
        var select = getSelectedValue(select1);
       	//alert(select);
        var allNodes = getAllNodes('marktable');
       var grade="";
                for (var tr in allNodes)
           	{
                	grade += allNodes[tr]["cells"][0]["children"][0].value+",";
                	//alert(allNodes[tr]["cells"][0]["children"][0].value);
                	//alert(allNodes[tr]["cells"][6]["children"][0].value + "哔哩哔哩");
                	
                /* 	if(!allNodes[tr]["cells"][6]["children"][0].value){
                		allNodes[tr]["cells"][6]["children"][0].value = "null";
                	}
                	if(!allNodes[tr]["cells"][7]["children"][0].value){
                		allNodes[tr]["cells"][7]["children"][0].value = "0";
                	}
                	if(!allNodes[tr]["cells"][8]["children"][0].value){
                		allNodes[tr]["cells"][8]["children"][0].value = "0";
                	}
                	if(!allNodes[tr]["cells"][9]["children"][0].value){
                		allNodes[tr]["cells"][9]["children"][0].value = "0";
                	}
                	grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
            		grade+= allNodes[tr]["cells"][7]["children"][0].value+",";
            		grade+= allNodes[tr]["cells"][8]["children"][0].value+","; */
            		
            		if(select=="五级制"){
            			grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
                		grade+= allNodes[tr]["cells"][7]["children"][0].value+",";
                		grade+= allNodes[tr]["cells"][8]["children"][0].value+",";
            			grade+= allNodes[tr]["cells"][9]["children"][0].value+",";
            		}else{
            			if(!allNodes[tr]["cells"][6]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
                    	}
            			if(!allNodes[tr]["cells"][7]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][7]["children"][0].value+",";
                    	}
            			if(!allNodes[tr]["cells"][8]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][8]["children"][0].value+",";
                    	}
            			
            		var type=allNodes[tr]["cells"][9]["children"][1].value;
            		if(type=="正常"){
            			if(!allNodes[tr]["cells"][9]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][9]["children"][0].value+",";
                    	}
            		}else if(type=="旷考"){
            			grade+="旷考,";
            		}else{
            			grade+="作弊,";
            		}
            		}
            		
            	}
            	//alert(grade);
        $.ajax({
            type:"POST",
            url:"${path}/teaScoreInput/saveGrade",
            dataType:"json",
            data:{
            	grade:grade,
            	testNo:"${testNo}",
            	testType:"${testType}",
            	usual:usual,
            	experiment:experiment,
            	final1:final1,
            	other:other,
            	select:select,
            	
            },
			success: function (data) {
                //alert("5555555");
                 window.location.href = "${path}/teaScoreInput/gradeSelected?testNo=${testNo}&usual="+usual+"&experiment="+experiment+"&final1="+final1+"&other="+other+"&select="+select+"&systemtemp=1"; 
            },
            error: function (data) {
                alert("学生成绩出错。");
                window.location.href = "${path}/teaScoreInput/index";
               
            },
         });  
    }
    
    function submitGrades(){
    
    	var usual=document.getElementById("num").value;
    	var experiment=document.getElementById("num2").value;
    	var final1=document.getElementById("num3").value;
        var other=document.getElementById("num4").value;
        var select1 = document.getElementById("select1");
        var select = getSelectedValue(select1);
       	//alert(select);
        var allNodes = getAllNodes('marktable');
       var grade="";
                for (var tr in allNodes)
           	{
                	grade += allNodes[tr]["cells"][0]["children"][0].value+",";
                	//alert(allNodes[tr]["cells"][0]["children"][0].value)
                	//alert(allNodes[tr]["cells"][6]["children"][0].value + "哔哩哔哩");
                	
                	/* if(!allNodes[tr]["cells"][6]["children"][0].value){
                		allNodes[tr]["cells"][6]["children"][0].value = "null";
                	}
                	if(!allNodes[tr]["cells"][7]["children"][0].value){
                		allNodes[tr]["cells"][7]["children"][0].value = "null";
                	}
                	if(!allNodes[tr]["cells"][8]["children"][0].value){
                		allNodes[tr]["cells"][8]["children"][0].value = "null";
                	}
                	if(!allNodes[tr]["cells"][9]["children"][0].value){
                		allNodes[tr]["cells"][9]["children"][0].value = "null";
                	}
                	grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
            		grade+= allNodes[tr]["cells"][7]["children"][0].value+",";
            		grade+= allNodes[tr]["cells"][8]["children"][0].value+",";
            		grade+= allNodes[tr]["cells"][9]["children"][0].value+","; */
            		
            		if(select=="五级制"){
            			grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
                		grade+= allNodes[tr]["cells"][7]["children"][0].value+",";
                		grade+= allNodes[tr]["cells"][8]["children"][0].value+",";
            			grade+= allNodes[tr]["cells"][9]["children"][0].value+",";
            		}else{
            			if(!allNodes[tr]["cells"][6]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
                    	}
            			if(!allNodes[tr]["cells"][7]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][7]["children"][0].value+",";
                    	}
            			if(!allNodes[tr]["cells"][8]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][8]["children"][0].value+",";
                    	}
            			
            		var type=allNodes[tr]["cells"][9]["children"][1].value;
            		if(type=="正常"){
            			if(!allNodes[tr]["cells"][9]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][9]["children"][0].value+",";
                    	}
            		}else if(type=="旷考"){
            			grade+="旷考,";
            		}else{
            			grade+="作弊,";
            		}
            		}
            		
            	}
            	//alert(grade);
        $.ajax({
            type:"POST",
            url:"${path}/teaScoreInput/submitGrade",
            dataType:"json",
            data:{
            	grade:grade,
            	testNo:"${testNo}",
            	testType:"${testType}",
            	usual:usual,
            	experiment:experiment,
            	final1:final1,
            	other:other,
            	select:select,
            	
            },
			success: function (data) {
               // alert("5555555");
                 window.location.href = "${path}/teaScoreInput/gradeSelected?testNo=${testNo}&usual="+usual+"&experiment="+experiment+"&final1="+final1+"&other="+other+"&select="+select+"&systemtemp=1"; 
            },
            error: function (data) {
                alert("学生成绩出错。");
                window.location.href = "${path}/teaScoreInput/index";
               
            },
         }); 
    }
    
    
     /* function submitGrades(){
      alert("submitGrades");
                $("#submitBt").attr("disabled", "disabled");
                $("#submitBt").addClass("disabled");
       	alert("000000000"); 
       var allNodes = getAllNodes('marktable');
        var passportNo;
       var grade="";
                for (var tr in allNodes)
           	{
                	grade += allNodes[tr]["cells"][0].innerHTML+",";
            		
                	grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
            		grade+= allNodes[tr]["cells"][7]["children"][0].value+",";
            		grade+= allNodes[tr]["cells"][8]["children"][0].value+",";
            		grade+= allNodes[tr]["cells"][9]["children"][0].value+",";
            		
            	}
            	alert(grade);
        $.ajax({
            type:"POST",
            url:"${path}/teaScoreInput/submitGrades",
            dataType:"json",
            data:{
            	grade:grade,
            	testNo:"${testNo}",
            	testType:"${testType}",
            	
            },

            success: function (data){
            	alert("submitGrades");
                $("#submitBt").attr("disabled", "disabled");
                $("#submitBt").addClass("disabled");
                $("#saveBt").attr("disabled", "disabled");
                $("#saveBt").addClass("disabled");
                $("#biliBt").attr("disabled", "disabled");
                $("#biliBt").addClass("disabled");
            },
            error: function(data) {
            	alert("error");
            }
         });   
    } */

     /*获取select的value*/
     function getSelectedValue(select){
 	    for(var i=0; i<select.options.length; i++){
 	       	if(select.options[i].selected)
 	       		return select.options[i].innerHTML;
         }
 	    return null;
     }

/* function doUpload(){

$.ajax({
            type:"POST",
            url:"${path}/teaScoreInput/importGrade",
            dataType:"json",
            
            success: function (data){
            	alert("success");
               
            },
            error: function(data) {
            	alert("error");
            }
         });   

} */
    </script>
    </body>
</html>
